package com.otod.pm.doc.web;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.otod.base.json.JsonSuccess;
import com.otod.commons.web.BaseController;
import com.otod.pm.doc.service.DocTpMasterService;
import com.otod.pm.doc.service.DocTpService;
import com.otod.pm.doc.service.PmDocItemService;
import com.otod.pm.doc.service.PmDocMasterService;
import com.otod.pm.doc.vo.PmDocItemVo;
import com.otod.pm.doc.vo.PmDocMasterVo;
import com.otod.pm.doc.vo.PmDocTpItemVo;
import com.otod.pm.doc.vo.PmDocTpMasterVo;



@Controller
@RequestMapping("pm/doc")
public class PmDocController extends BaseController {
	
	@Autowired
	private PmDocItemService pmDocItemService;
	@Autowired
	private PmDocMasterService pmDocMasterService;
	@Autowired
	private DocTpMasterService docTpMasterService;
	@Autowired
	private DocTpService docTpService;
	
	
	/**保存文档章节
	 * @param taskType  任务类型
	 * @param stepId  阶段id
	 * @param itemId  章节id
	 * @param taskId  任务id
	 * @param masterId  文档id
	 * @param parentId  父级id
	 * @return
	 */
	@RequestMapping(value="saveItemMaster",method=RequestMethod.POST)
	@ResponseBody
	public String saveItemMaster(String taskType,String stepId,String itemId,String taskId,String masterId,String parentId){
		
		//通过章节的id查询章节的名字
		PmDocTpItemVo pmDocTpItemVo =  docTpService.getById(itemId);
		//通过文档的id查询文档的名字
		PmDocTpMasterVo pmDocTpMasterVo = docTpMasterService.getById(masterId);
		
		//分别分装数据进行添加
		PmDocMasterVo pmDocMasterVo = new PmDocMasterVo();
		pmDocMasterVo.setDocName(pmDocTpMasterVo.getTpName());
		pmDocMasterVo.setDocType(taskType);
		pmDocMasterVo.setStepId(stepId);
		pmDocMasterVo.setTpItemId(pmDocTpMasterVo.getUuid());
		super.setInsertOperInfo(pmDocMasterVo);
		
		PmDocItemVo pmDocItemVo = new PmDocItemVo();
		pmDocItemVo.setItemName(pmDocTpItemVo.getTitle());
		pmDocItemVo.setTaskId(taskId);
		super.setInsertOperInfo(pmDocItemVo);
		pmDocItemVo.setEmpNo("");
		pmDocItemVo.setIndexNo(pmDocTpItemVo.getIndexNo());
		
		
		pmDocItemService.saveDocItem(pmDocMasterVo,pmDocItemVo);
		
		

		return JsonSuccess.factory("保存章节成功");
	}
	
	
	
}
